package com.tfswx.fljdmxyy.taskContext;

import com.tfswx.fljdmxyy.constant.SystemConstant;
import com.tfswx.fljdmxyy.dao.RwXtPzMapper;
import com.tfswx.fljdmxyy.query.rwpz.RwpzQueryParam;
import com.tfswx.fljdmxyy.model.RwXtPz;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

/**
 * 运行任务
 *
 * @Author 陈文佳
 * @Date 2023/03/24
 */
@Slf4j
@Component
public class TaskAutoRunnable implements ApplicationRunner {

    @Resource
    private TaskConfigurer taskConfigurer;

    @Resource
    private RwXtPzMapper rwxtpzMapper;

    @Override
    public void run(ApplicationArguments args) {
        try {
            log.info("================项目启动初始化定时任务====开始==========");
            RwpzQueryParam queryInputDTO = new RwpzQueryParam();
            queryInputDTO.setSfqy(SystemConstant.Y);
            queryInputDTO.setSfzt(SystemConstant.N);
            List<RwXtPz> tasks = rwxtpzMapper.queryRwpz(queryInputDTO);
            log.info("定时任务开始执行 ,初始化任务数【{}】", tasks.size());
            taskConfigurer.refreshTask(tasks);
            log.info("================项目启动初始化定时任务====完成==========");
        } catch (Exception ex) {
            log.error("================项目启动初始化定时任务====异常：{}", ex);
        }
    }
}
